package Classes;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Owner
 */
import javax.swing.*;
import javax.swing.Timer;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;

public class DateTime {
    Calendar calendar;
    public DateTime() {
        calendar = Calendar.getInstance();
    }

    public String getCurrentTime() {
        calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR);
        if(hour == 0) {
            hour = 12;
        }
        return  hour + ":" + checkTime(calendar.get(Calendar.MINUTE)) 
                + " " + amPm(calendar.get(Calendar.AM_PM));
    }
    
    public String getCurrentDate() {
        calendar = Calendar.getInstance();
        return setMonth(calendar.get(Calendar.MONTH) + 1) 
                + " " + calendar.get(Calendar.DAY_OF_MONTH) 
                + " " + calendar.get(Calendar.YEAR);
    }
    
    public String getDBDate() {
        calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR) 
                + "-" + setDBMonth(calendar.get(Calendar.MONTH) + 1) 
                + "-" + calendar.get(Calendar.DAY_OF_MONTH);
    }
    
    public String getCurrDate() {
        calendar = Calendar.getInstance();
        return setDBMonth(calendar.get(Calendar.MONTH) + 1)  
                + "-" + checkTime(calendar.get(Calendar.DAY_OF_MONTH))
                + "-" + calendar.get(Calendar.YEAR);
    }
    
    public String getCurrYear() {
        calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR) 
                + "-" + (calendar.get(Calendar.YEAR ) + 1); 
    }
    
    public String getYear() {
        calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR) + ""; 
    }
    
    public String getMonth() {
        calendar = Calendar.getInstance();
        return setMonth(calendar.get(Calendar.MONTH) + 1) + "";
    }
    
    public String getDate() {
        calendar = Calendar.getInstance();
        return getMonth() + "-" + calendar.get(Calendar.DAY_OF_MONTH) + "-" + getYear();
    }


    public String checkTime(int t) {
        String time1;
        if (t < 10) {
            time1 = ("0" + t);
        } else {
            time1 = ("" + t);
        }
        return time1;
    }

    public String amPm(int ap) {
        String amPm;
        if (ap == 0)
            amPm = "AM";
        else
            amPm = "PM";
        return amPm;
    }
    
    public String setMonth(int a) {
        //String s = "Jan";
        switch(a) {
            case 1:
                return "Jan";
            case 2:
                return "Feb";
            case 3:
                return "Mar";
            case 4:
                return "Apr";
            case 5:
                return "May";
            case 6:
                return "Jun";
            case 7:
                return "Jul";
            case 8:
                return "Aug";
            case 9:
                return "Sep";
            case 10:
                return "Oct";
            case 11:
                return "Nov";                                  
        }
        return "Dec";
    }
    
    public String setDBMonth(int a) {
        //String s = "Jan";
        switch(a) {
            case 1:
                return "01";
            case 2:
                return "02";
            case 3:
                return "03";
            case 4:
                return "04";
            case 5:
                return "05";
            case 6:
                return "06";
            case 7:
                return "07";
            case 8:
                return "08";
            case 9:
                return "09";
            case 10:
                return "10";
            case 11:
                return "11";                                  
        }
        return "12";
    }
    
    // combobox
     public String getRealYear() {
        GregorianCalendar cal = new GregorianCalendar();
        int realYear = cal.get(GregorianCalendar.YEAR) - 6;        
        return String.valueOf(realYear);       
    }
        
    public String getPrevYear() {
        GregorianCalendar cal = new GregorianCalendar();
        int prevYear = cal.get(GregorianCalendar.YEAR) - 7;
        return String.valueOf(prevYear); 
    }
    
    // label
    public int getToday() {        
        calendar = Calendar.getInstance();
        int today = calendar.get(Calendar.YEAR);
        System.out.println(today);
        return today;
    }
    
    public int getNext() {        
        calendar = Calendar.getInstance();
        int next = calendar.get(Calendar.YEAR) + 1;
        System.out.println(next);
        return next;
    }
    
    public int getPast() {                
        calendar = Calendar.getInstance();
        int past = calendar.get(Calendar.YEAR) - 1;
        System.out.println(past);
        return past;
    }

}
